package icu.qx.gbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.gbs.domain.GbsGoodUrl;
import icu.qx.gbs.service.IGbsGoodUrlService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物品图片Controller
 *
 * @author yong
 * @date 2024-06-30
 */
@RestController
@RequestMapping("/gbs/url")
public class GbsGoodUrlController extends BaseController {
    @Autowired
    private IGbsGoodUrlService gbsGoodUrlService;

    /**
     * 查询物品图片列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GbsGoodUrl gbsGoodUrl) {
        startPage();
        List<GbsGoodUrl> list = gbsGoodUrlService.selectGbsGoodUrlList(gbsGoodUrl);
        return getDataTable(list);
    }

    /**
     * 导出物品图片列表
     */
    @Log(title = "物品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GbsGoodUrl gbsGoodUrl) {
        List<GbsGoodUrl> list = gbsGoodUrlService.selectGbsGoodUrlList(gbsGoodUrl);
        ExcelUtil<GbsGoodUrl> util = new ExcelUtil<GbsGoodUrl>(GbsGoodUrl.class);
        util.exportExcel(response, list, "物品图片数据");
    }

    /**
     * 获取物品图片详细信息
     */
    @GetMapping(value = "/{urlId}")
    public AjaxResult getInfo(@PathVariable("urlId") Long urlId) {
        return success(gbsGoodUrlService.selectGbsGoodUrlByUrlId(urlId));
    }

    /**
     * 新增物品图片
     */
    @Log(title = "物品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GbsGoodUrl gbsGoodUrl) {
        return toAjax(gbsGoodUrlService.insertGbsGoodUrl(gbsGoodUrl));
    }

    @Log(title = "物品图片", businessType = BusinessType.INSERT)
    @PostMapping("/list")
    public AjaxResult addList(@RequestBody List<GbsGoodUrl> gbsGoodUrls) {
        return toAjax(gbsGoodUrlService.insertGbsGoodUrls(gbsGoodUrls));
    }

    /**
     * 修改物品图片
     */
    @Log(title = "物品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GbsGoodUrl gbsGoodUrl) {
        return toAjax(gbsGoodUrlService.updateGbsGoodUrl(gbsGoodUrl));
    }

    /**
     * 删除物品图片
     */
    @Log(title = "物品图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{urlIds}")
    public AjaxResult remove(@PathVariable Long[] urlIds) {
        return toAjax(gbsGoodUrlService.deleteGbsGoodUrlByUrlIds(urlIds));
    }
}
